﻿
Imports System.Data.SqlClient
Imports AppsUtility.EncDec
Imports System.Configuration
Public Class frmServiceJournalReport

    Dim util As New AppsUtility.EncDec
    Public strCon As String = util.toDecrypt(System.Configuration.ConfigurationManager.AppSettings("SQLString"))
    Dim SqlCon As New SqlConnection(strCon)

    Dim SerJourId As Integer

    Private Sub frmServiceJournal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call toLoadCustomers()
    End Sub

    Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
        Me.Cursor = Cursors.WaitCursor
        Dim DateFrom, DateTo As String
        DateFrom = dtpDateFrom.Value.ToString("yyyy-MM-dd")
        DateTo = dtpDateTo.Value.ToString("yyyy-MM-dd")
        Call toLoadServiceJournalReport(cmbCustomer.SelectedValue, DateFrom, DateTo)
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub

    Sub toLoadServiceJournalReport(ByVal CusCode As String, ByVal DateFrom As String, ByVal DateTo As String)
        Try

            Dim StrSQL As String
            Dim da As New SqlDataAdapter
            Dim ds As New Service

            Dim cryserjour As New CrySerJour

            StrSQL = "select b.CUSNAME,b.CUSCODE ,c.Salesman,d.TypeName,e.LocName ,a.DoneBy,a.Remarks  from ServiceJournal a, Customer b, Salesman c,ServiceType d,ServiceLocation e  where a.CusCode=b.CUSCODE and a.SalesmanId=c.SalesmanId and a.SerTypeId=d.TypeId and a.SerLoc=e.LocId and b.CUSCODE like '" & CusCode & "' and a.DoneBy between '" & DateFrom & "' and '" & DateTo & "' "

            da.SelectCommand = New SqlCommand(StrSQL, SqlCon)
            da.Fill(ds.Tables("SerJourRpt"))

            cryserjour.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = cryserjour


        Catch ex As Exception
            MsgBox(ex.ToString, 16, "Inventory Manager")
        End Try
    End Sub

    Sub toLoadCustomers()
        Try
            Dim StrSQL As String
            StrSQL = "Select CusName,CusCode from Customer"

            Dim da As New SqlDataAdapter(StrSQL, SqlCon)
            Dim ds As New DataSet("Customer")
            da.Fill(ds, "Customer")

            cmbCustomer.DataSource = ds.Tables(0)
            cmbCustomer.DisplayMember = "CusName"
            cmbCustomer.ValueMember = "CusCode"

            Dim dRow As DataRow
            dRow = ds.Tables(0).NewRow()
            dRow("CusCode") = "%"
            dRow("CusName") = "All Customers"
            ds.Tables(0).Rows.Add(dRow)

            cmbCustomer.SelectedText = "All Customers"

        Catch ex As Exception
            MsgBox(ex.ToString, 16, "Inventory Manager")
        End Try
    End Sub


End Class